﻿(function ($) {

    $.util.namespace("mainpage.authmenus");

    //测试使用，具体数据源在 /Common/menus-data.json
    window.mainpage.authmenus.data = [
        {
            id: 1, text: "Base", code: "10", iconCls: "icon-unknow", attributes: { code: "10", href: "" },
            children: [
                { id: 22, text: "遮罩层", code: "1001", iconCls: "icon-unknow", attributes: { code: "1001", href: "/Base/LoadingIndex" } }
            ]
        },
        {
            id: 5, text: "Datagrid", code: "20", iconCls: "icon-unknow", attributes: { code: "20", href: "" },
            children: [
                { id: 22, text: "导出到Excel", code: "2099", iconCls: "icon-unknow", attributes: { code: "2099", href: "/Datagrid/ExportToExcelIndex" } }
            ]
        }
    ];

    window.mainpage.authmenus.getWestRootMenus = function (callback) {
        $.getJSON("/Common/menus-data.json", function (json) {
            var data = json.filter(function (item) { return $.string.isNullOrWhiteSpace(item.attributes.href) && item.attributes.position == "west"; });
            if ($.isFunction(callback)) { callback.call(this, data); }
        });
    };

    window.mainpage.authmenus.getEastRootMenus = function (callback) {
        $.getJSON("/Common/menus-data.json", function (json) {
            var data = json.filter(function (item) { return $.string.isNullOrWhiteSpace(item.attributes.href) && item.attributes.position == "east"; });
            if ($.isFunction(callback)) { callback.call(this, data); }
        });
    };

    window.mainpage.authmenus.getChildrenMenus = function (id, code, callback) {
        $.getJSON("/Common/menus-data.json", function (json) {
            var parent = json.first(function (item) { return item.id == id });
            var data = parent ? (parent.children ? parent.children : []) : [];
            if ($.isFunction(callback)) { callback.call(this, data); }
        });
    };

})(jQuery);